package com.ruoyi.web.controller.assets;

import com.ruoyi.assets.dto.StateVisitDTO;
import com.ruoyi.assets.queue.service.MessageProducer;
import com.ruoyi.assets.service.IStateVisitService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 访问记录Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/assets/visit")
public class StateVisitController extends BaseController {
    @Autowired
    private IStateVisitService stateVisitService;
    @Autowired
    private MessageProducer messageProducer;

    /**
     * 获取今日访问量
     */
    @GetMapping("/today")
    public AjaxResult getTodayVisits() {
        return success(stateVisitService.selectTodayTotalVisits());
    }
    
    /**
     * 获取月度访问量趋势
     */
    @GetMapping("/monthly")
    public AjaxResult getMonthlyVisits() {
        List<Map<String, Object>> trends = stateVisitService.getMonthlyVisitTrends(12);
        return success(trends);
    }
    
    /**
     * 记录资产访问
     */
    @PostMapping("/record/{assetId}")
    public AjaxResult recordVisit(@PathVariable("assetId") Long assetId) {
        return toAjax(stateVisitService.recordVisit(assetId));
    }
} 